package top.sigetech.fmallh.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.sigetech.fmallh.dao.UserRepo;
import top.sigetech.fmallh.entity.User;
import top.sigetech.fmallh.service.IUserService;

import java.util.Optional;

/**
 * 测试类接口实现类
 * @author cores
 */
@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    UserRepo userRepo;
    /**
     * 增删改事务添加
     * 增方法  单纯只在测试表新增 一条记录
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void addUser() {
        User user = new User();
        user.setUsername("test");
        user.setPassword("test");
        userRepo.save(user);
    }

    @Override
    public User getUser(){
        Optional<User> user = userRepo.findById(1);
        return user.orElse(null);
    }
}
